$INCLUDE: 'C:\FG\FASTGRAF.FI'

C  This program will work with Microsoft FORTRAN 4.x/5.x only.  For a
C  Microsoft FORTRAN PowerStation version of this program, see the file
C  08-14PS.FOR.

      PROGRAM MAIN

      INTEGER WIDTH, HEIGHT
      PARAMETER (WIDTH = 640, HEIGHT = 400)

      INTEGER HANDLE, OLD_MODE, STATUS
      INTEGER FG_GETMODE, FG_VBALLOC, FG_VBOPEN

C  Initialize the video environment

      CALL FG_INITPM
      OLD_MODE = FG_GETMODE()
      CALL FG_SETMODE(19)
      CALL FG_VBINIT

C  Set up a 640x400 virtual buffer

      HANDLE = FG_VBALLOC(WIDTH,HEIGHT)
      IF (HANDLE .LT. 0) THEN
         CALL FG_SETMODE(OLD_MODE)
         CALL FG_RESET
         STOP 'Could not create the virtual buffer.'
      END IF
      STATUS = FG_VBOPEN(HANDLE)

C  Draw a 320x200 rectangle in each virtual buffer quadrant

      CALL FG_SETCOLOR(9)
      CALL FG_RECT(0,319,0,199)
      CALL FG_SETCOLOR(10)
      CALL FG_RECT(320,639,0,199)
      CALL FG_SETCOLOR(11)
      CALL FG_RECT(0,319,200,399)
      CALL FG_SETCOLOR(12)
      CALL FG_RECT(320,639,200,399)

C  Paste each rectangle to the 320x200 active video page

      CALL FG_VBPASTE(0,319,0,199,0,199)
      CALL FG_WAITKEY
      CALL FG_VBPASTE(320,639,0,199,0,199)
      CALL FG_WAITKEY
      CALL FG_VBPASTE(0,319,200,399,0,199)
      CALL FG_WAITKEY
      CALL FG_VBPASTE(320,639,200,399,0,199)
      CALL FG_WAITKEY

C  Paste the center 320x200 subset of the virtual buffer

      CALL FG_VBPASTE(160,479,100,299,0,199)
      CALL FG_WAITKEY

C  Close the virtual buffer

      CALL FG_VBCLOSE
      CALL FG_VBFREE(HANDLE)

C  Restore original video mode and exit

      CALL FG_SETMODE(OLD_MODE)
      CALL FG_RESET

      STOP ' '
      END
